﻿using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Net;
using System.Text;

namespace wikisoft.onlineCoding.css
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class getRemoteCss : IHttpHandler
    {
        private HttpContext m_Context;

        public void ProcessRequest(HttpContext context)
        {
            m_Context = context;
            string url=m_Context.Request["url"];
            if(!string.IsNullOrEmpty(url)) 
            GetCssFile(url);
        }

        private void GetCssFile(string url)
        {
            WebClient client = new WebClient();
            //client.Encoding = Encoding.UTF8;
            client.UseDefaultCredentials = true;
            client.DownloadStringAsync(new Uri(url));
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            m_Context.Response.ContentType = "text/plain";
            m_Context.Response.Write(e.Result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
